//
//  YQShareJsApi4.m
//  industry
//
//  Created by 王雅强 on 2021/2/7.
//  Copyright © 2021 Haier. All rights reserved.
//

#import "YQShareJsApi4.h"
#import "YQShareSheetView.h"
#import "WXApi.h"

#define shareUrl @"http://10.227.217.101:8081/#"

@interface YQShareJsApi4()

@property (nonatomic, strong) YQShareSheetView *sheetView;

@end

@implementation YQShareJsApi4


/*
 desc:"成相应邀请您查看我的名片"
 myprop:"card_share"
 path:"page/index/index"
 query:"http://10.227.217.101:8080/#/?userId=15&employeeName=成相应&lastLoginCompanyName=海尔融资租赁股份有限公司"
 title:"我的名片"
 */

//重写父类方法
- (void)handler:(NSDictionary *)data context:(PSDContext *)context callback:(PSDJsApiResponseCallbackBlock)callback {
    [super handler:data context:context callback:callback];
    if (!data) {
        ErrorCallback(callback, e_inavlid_params);
        return;
    } else {
        XLLog(@"分享按钮回调%@",data);
        if ([data[@"myprop"] isEqual: @"card_share"]) {
            
            
            WXWebpageObject *webpageObject = [WXWebpageObject object];
            
            webpageObject.webpageUrl = data[@"query"];
            
            WXMediaMessage *message = [WXMediaMessage message];
            message.title = data[@"title"];
            message.description = data[@"desc"];
            NSArray *iconsArr = [[NSBundle mainBundle] infoDictionary][@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconFiles"];
            [message setThumbImage:[UIImage imageNamed:iconsArr.lastObject]];
            message.mediaObject = webpageObject;
            
            SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
            req.bText = NO;
            req.message = message;
            req.scene = WXSceneSession;
            
            if (!self.sheetView) {
                self.sheetView = [[YQShareSheetView alloc]init];
            }
            
            
            [self.sheetView addSheetView];
            [self.sheetView setWeiXinAC:^{
                req.scene = WXSceneSession;
                
                [WXApi sendReq:req completion:^(BOOL success) {
                    XLLog(@"微信分享成功");
                }];
                
            } pyqAC:^{
                req.scene = WXSceneTimeline;
                
                [WXApi sendReq:req completion:^(BOOL success) {
                    XLLog(@"朋友圈分享成功");
                }];
                
            }];
        }
            
    }
}


@end
